﻿namespace YawetagLib.Web.Utilities
{
    public static class HtmlBuilder
    {
        public static string StyleReference(string name, bool tempRelative)
        {
            return string.Format("<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />",
                ResourceProvider.GetResourcePath(name, tempRelative));
        }

        public static string StyleReference(string path, string name, bool tempRelative)
        {
            return string.Format("<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />",
                !path.Contains("http://") ? ResourceProvider.GetLocalResourcePath(path, name, tempRelative) : path);
        }

        public static string ScriptReference(string name)
        {
            return string.Format("<script src=\"{0}\" type=\"text/javascript\" language=\"javascript\"></script>",
                ResourceProvider.GetResourcePath(name));
        }

        public static string ScriptReference(string path, string name)
        {
            return string.Format("<script src=\"{0}\" type=\"text/javascript\" language=\"javascript\"></script>",
                !path.Contains("http://") ? ResourceProvider.GetLocalResourcePath(path, name) : path);
        }

        public static string Image(string path, string name, bool tempRelative, object htmlAttributes)
        {
            return string.Format("<img src=\"{0}\" {1} />", 
                !path.Contains("http://") ? ResourceProvider.GetLocalResourcePath(path, name, tempRelative) : path, 
                htmlAttributes.ToTagHtmlAttributes());
        }

        public static string Image(string name, bool tempRelative, object htmlAttributes)
        {
            return string.Format("<img src=\"{0}\" {1} />",
                ResourceProvider.GetResourcePath(name, tempRelative), htmlAttributes.ToTagHtmlAttributes());
        }

        public static string Hyperlink(string name, object htmlAttributes)
        {
            string attributes = htmlAttributes.ToTagHtmlAttributes();

            if (!attributes.Contains("href="))
            {
                attributes += " href='javascript:void(0)'";
            }

            return string.Format("<a {0}>{1}</a>", attributes, name);
        }
    }
}
